<?php
	require('config.php');
	$wb_id=$_REQUEST['wb_id'];
	$sql="select ".$oto."_help_order_user.*,".$oto."_users.userPhoto,".$oto."_users.userName from `".$oto."_help_order_user`,".$oto."_users where `help_id`='{$wb_id}' and ".$oto."_help_order_user.isDel='0' and ".$oto."_help_order_user.user_id=".$oto."_users.userId order by ".$oto."_help_order_user.createTime ASC";
	//file_put_contents("tsxx.txt", "\r\n".$sql."\r\n", FILE_APPEND);
	$result=$db->query($sql);
	while($row=$result->fetch_assoc()){
		$order_user[]=$row;//将取得的所有数据赋值给person_info数组
	}
	$sql="select * from ".$oto."_help_orders where helpId='{$wb_id}' and isDel='0' and orderStatus not in ('-1','-2','-5','-6')";
	$result=$db->query($sql);
	while($row=$result->fetch_assoc()){
		$isOrder[]=$row;//将取得的所有数据赋值给person_info数组
	}
	if(isset($order_user))
	{
		for($i=0;$i<count($order_user);$i++)
		{
			$user_id=$order_user[$i]['user_id'];
			$sql="select * from ".$oto."_help_chat where helpId='{$wb_id}' and userId='{$user_id}' and isDel='0' order by createTime DESC";
			$result=$db->query($sql);
			while($row=$result->fetch_assoc()){
				$help_chat[$i][]=$row;//将取得的所有数据赋值给person_info数组
			}
			if(isset($help_chat[$i]))
			{
				$order_user[$i]['chat']=$help_chat[$i][0]['content'];
			}
			else
			{
				$order_user[$i]['chat']='';
			}
			$sql="select * from ".$oto."_help_orders where helpId='{$wb_id}' and acceptUserId='{$user_id}' and isDel='0' and orderStatus not in ('-1','-2','-5','-6')";
			$result=$db->query($sql);
			while($row=$result->fetch_assoc()){
				$isXuan[$i][]=$row;//将取得的所有数据赋值给person_info数组
			}
			if(isset($isXuan[$i]))
			{
				$order_user[$i]['isXuan']=1;
			}
			else $order_user[$i]['isXuan']=0;
		}
		if(isset($isOrder))
		{
			$order_user[0]['isGo']=0;
		}
		else $order_user[0]['isGo']=1;
		echo json_encode($order_user);
	}
	else echo "[]";
?>